package com.blog.admin.listener;

import com.blog.admin.listener.event.CacheEvent;
import com.blog.admin.service.FileInfoService;
import com.blog.common.redis.service.RedisService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <p>
 * 事件监听器
 * </p>
 *
 * @author Valerie
 * @date 2023/6/3
 **/
@EnableAsync
@Component
@Slf4j
@AllArgsConstructor
public class AsyncTaskListener {


    private final FileInfoService fileInfoService;



    @EventListener
    @Async
    public void onApplicationEvent(CacheEvent cacheEvent) {
        fileInfoService.refreshFileInfoList(cacheEvent.getKey());
        log.warn("事件监听器执行！->{}", cacheEvent.getLocalDateTime());
    }

}
